<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item v-if="judgeShow('tk001')" label="预付款单别">
				<u-input v-model="infoObj.tk001" placeholder="请输入预付款单别" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk002')" label="预付款单号">
				<u-input v-model="infoObj.tk002" placeholder="请输入预付款单号" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk015')" label="拟支付日期">
				<u-input v-model="infoObj.tk015" placeholder="拟支付日期" :disabled="judgeWrite('tk015')"></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk003')" label="付款日期">
				<u-input v-model="infoObj.tk003" placeholder="请输入付款日期" :disabled="judgeWrite('tk003')"></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk022')" label="单据日期">
				<u-input v-model="infoObj.tk022" placeholder="请输入单据日期" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk043')" label="应付对象">
				<u-input v-model="infoObj.tk043" placeholder="请输入应付对象" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk004')" label="预付对象编号" labelWidth='180'>
				<u-input v-model="infoObj.tk004" placeholder="请输入预付对象编号" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk010')" label="结算方式编号" labelWidth='180'>
				<view style="width: 30rpx;"><u-input v-model="infoObj.tk010" placeholder="请输入结算方式编号" disabled></u-input>
				</view>票据
			</u-form-item>
			<u-form-item v-if="judgeShow('tk013')" label="结算科目">
				<u-input v-model="infoObj.tk013" placeholder="请输入结算科目" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk013name')" label="科目名称">
				<u-input v-model="infoObj.tk013name" placeholder="请输入科目名称" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('ma028')" label="付款账号">
				<u-input v-model="infoObj.ma028" placeholder="请输入付款账号" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('udf03')" label="银号名称">
				<u-input v-model="infoObj.udf03" placeholder="请输入银号名称" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk044')" label="应付对象简称" labelWidth='180'>
				<u-input v-model="infoObj.tk044" placeholder="请输入应付对象简称" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk007')" label="币种">
				<u-input v-model="infoObj.tk007" placeholder="请输入币种" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk008')" label="汇率">
				<u-input v-model="infoObj.tk008" placeholder="请输入汇率" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk005')" label="人员">
				<u-input v-model="infoObj.tk005" placeholder="请输入人员" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk006')" label="部门">
				<u-input v-model="infoObj.tk006" placeholder="请输入部门" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk023')" label="审核者">
				<u-input v-model="infoObj.tk023" placeholder="请输入审核者" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk020')" label="生成分录">
				<u-input v-model="infoObj.tk020" placeholder="请输入生成分录" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk028')" label="核销状态">
				<u-input v-model="infoObj.tk028" placeholder="请输入核销状态" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk019')" label="打印次数">
				<u-input v-model="infoObj.tk019" placeholder="请输入打印次数" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk016')" label="账款科目">
				<u-input v-model="infoObj.tk016" placeholder="请输入账款科目" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('tk016name')" label="科目名称">
				<u-input v-model="infoObj.tk016name" placeholder="请输入科目名称" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk017')" label="采购单单别">
				<u-input v-model="infoObj.tk017" placeholder="请输入采购单单别" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk018')" label="采购单单号">
				<u-input v-model="infoObj.tk018" placeholder="请输入采购单单号" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk024')" label="签核状态码">
				<u-input v-model="infoObj.tk024" placeholder="请输入签核状态码" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('tk019')" label="上次重估汇率" labelWidth='180'>
				<u-input v-model="infoObj.tk019" placeholder="请输入上次重估汇率" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk027')" label="项目编号">
				<u-input v-model="infoObj.tk027" placeholder="请输入项目编号" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk025')" label="累计调汇金额" labelWidth='200'>
				<u-input v-model="infoObj.tk025" placeholder="请输入累计调汇金额" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk030')" label="原币预付金额" labelWidth='200'>
				<u-input v-model="infoObj.tk030" placeholder="请输入原币预付金额" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('udf06')" label="金额大写">
				<u-input v-model="infoObj.udf06" placeholder="请输入金额大写" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk031')" label="本币预付金额" labelWidth='200'>
				<u-input v-model="infoObj.tk031" placeholder="请输入本币预付金额" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk032')" label="原币已核销金额" labelWidth='200'>
				<u-input v-model="infoObj.tk032" placeholder="请输入原币已核销金额" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk033')" label="本币已核销金额" labelWidth='200'>
				<u-input v-model="infoObj.tk033" placeholder="请输入本币已核销金额" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tk009')" label="付款摘要">
				<u-input v-model="infoObj.tk009" placeholder="请输入付款摘要" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('udf05')" label="备注">
				<u-input v-model="infoObj.udf05" type="textarea" placeholder="请输入备注"></u-input>
			</u-form-item>
		</u-form>
	</view>
</template>

<script>
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update,
	} from '@/api/apply/order'
	import {
		getAdvancePaymentWithFlowInfo
	} from '@/api/workFlow/flowBefore.js'
	import {
		getDictionaryDataSelector,
		getDataInterfaceDataInfo
	} from '@/api/common'
	export default {
		mixins: [comMixin],
		data() {
			return {
				buyName: '',
				buyNameTwo: '',
				categoriesOfTaxesName: '',
				categoriesOfTaxesLst: [],
				tel: '', //联系人
				telTwo: '', //联系人
				hide: false,
				billEnCode: 'OrderNumber',
				dataForm: {},
				infoObj: {},
				lst: [],
				dictionaryInfo: {},
				info: {},
				formConf: {},
				listInfo: {
					optionOne: '',
					optionTwo: '',
					optionThree: '',
					optionFour: '',
					JoinStr: '',
					gochang: '',
				},
				id: '',
			}
		},
		methods: {
			init(data, id, flowFormContentJson) {
				this.setting = data
				this.id = id
				this.getInfoFn(data)
			},
			getInfoFn(data) {
				getAdvancePaymentWithFlowInfo(data.id).then(res => {
					if (res.code == 200) {
						this.infoObj = res.data
						this.getDictionaryDataSelectorOne() //生产分录字段
						this.getDictionaryDataSelectorTwo() //核销状态字段
						this.getDictionaryDataSelectorThree() //签核状态码字段
						this.getDictionaryDataSelectorFour() //应付对象字段
						this.getDataInterfaceDataInfoMA003(this.infoObj.tk007) //币种
						this.getDataInterfaceDataInfoMA004(this.infoObj.tk006) //部门
						this.getDataInterfaceDataInfoMA005(this.infoObj.tk005) //人员

					}
				})
			},
			/**
			 * 生产分录字段
			 */
			getDictionaryDataSelectorOne() {
				getDictionaryDataSelector('430971722078988805').then(res => {
					if (res.code == 200) {

						res.data.list.forEach(res => {
							if (res.enCode == this.infoObj.tk020) {
								this.infoObj.tk020 = res.fullName
							}
						})
					}
				})
			},
			/**
			 * 核销状态字段
			 */
			getDictionaryDataSelectorTwo() {
				getDictionaryDataSelector('430971986139785733').then(res => {
					if (res.code == 200) {

						res.data.list.forEach(res => {
							if (res.enCode == this.infoObj.tk028) {
								this.infoObj.tk028 = res.fullName
							}
						})
					}
				})
			},
			/**
			 * 签核状态码字段
			 */
			getDictionaryDataSelectorThree() {
				getDictionaryDataSelector('393566623006470277').then(res => {
					if (res.code == 200) {

						res.data.list.forEach(res => {
							if (res.enCode == this.infoObj.tk024) {
								this.infoObj.tk024 = res.fullName
							}
						})
					}
				})
			},
			/**
			 * 应付对象字段
			 */
			getDictionaryDataSelectorFour() {
				getDictionaryDataSelector('431244454284864197').then(res => {
					if (res.code == 200) {

						res.data.list.forEach(res => {
							if (res.enCode == this.infoObj.tk043) {
								this.infoObj.tk043 = res.fullName
							}
						})
					}
				})
			},
			getDataInterfaceDataInfoMV002(id) {
				let data = {
					id,
					interfaceId: '362118781926906437',
					dblink: this.id,
					propsValue: 'MA001',
					relationField: 'MA002',
				}
				getDataInterfaceDataInfo('362118781926906437', data).then(res => {
					if (res.code == 200) {
						this.buyName = res.data.JoinStr
						this.infoObj.tc004 = res.data.MA002
						console.log('buyName', res)
					}
				})
			},
			getDataInterfaceDataInfoMA003(id) {
				let data = {
					id,
					interfaceId: '362115609221143109',
					dblink: this.id,
					propsValue: 'MF001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('362115609221143109', data).then(res => {
					if (res.code == 200) {
						this.infoObj.tk007 = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfoMA004(id) {
				let data = {
					id,
					interfaceId: '362111557984852549',
					dblink: this.id,
					propsValue: 'ME001',
					relationField: 'JoinStr',
				}

				getDataInterfaceDataInfo('362111557984852549', data).then(res => {
					if (res.code == 200) {
						this.infoObj.tk006 = res.data.JoinStr || ''

					}
				})
			},

			getDataInterfaceDataInfoMA005(id) {
				let data = {
					id,
					interfaceId: '428345732257285957',
					dblink: this.id,
					propsValue: 'MV001',
					relationField: 'JoinStr',
				}

				getDataInterfaceDataInfo('428345732257285957', data).then(res => {
					if (res.code == 200) {
						this.infoObj.tk005 = res.data.JoinStr || ''
					}
				})
			},

			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
			selfInit() {
				this.addGoods()
				this.addPlan()
			},
			onChange(e) {
				const user = e[0]
				this.dataForm.salesmanName = user.fullName
			},
			addGoods() {
				const item = {
					goodsId: '',
					goodsCode: '',
					goodsName: '',
					specifications: '',
					unit: '',
					qty: '',
					price: '',
					amount: '',
					discount: null,
					cess: null,
					actualPrice: '',
					actualAmount: '',
					description: ''
				}
				this.dataForm.goodsList.push(item)
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1)
			},
			addPlan() {
				const item = {
					receivableDate: '',
					receivableRate: '',
					receivableMoney: '',
					receivableMode: '',
					abstract: ''
				}
				this.dataForm.collectionPlanList.push(item)
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1)
			},
			onGoodsChange(e, i) {
				const goods = e[0]
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: ''
				}
				this.$forceUpdate()
			},
			onCustomerChange(e) {
				const customer = e[0]
				this.dataForm.customerName = customer.text
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(parseFloat(row.price) * parseFloat(row.qty))
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(discountPrice * (1 + (row.cess / 100)));
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(parseFloat(row.actualPrice) * parseFloat(row
					.qty))
				this.$forceUpdate()
			}
		}
	}
</script>